package com.dayu.web.controller;

import java.util.HashSet;
import java.util.Set;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dayu.finecomm.protocol.codec.Drive;
import com.dayu.utils.ReflectionUtils;
import com.dayu.web.param.TokenParam;
import com.dayu.web.vo.RESTResponse;

/**
 * 关于协议
 * 
 * @author Chenjiawei
 *
 *         2017年6月12日
 */
@Controller
@RequestMapping("/unitalk/v1.0")
public class DriveCtrl {

	/**
	 * 获取协议接口
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/drives.json", method = { RequestMethod.POST })
	public String getDrives(@RequestBody TokenParam token) {

		Set<Class<?>> set = ReflectionUtils.getClassOf(
				"com.dayu.finecomm.device", Drive.class);
		Set<String> drives = new HashSet<>();

		for (Class<?> clazz : set) {

			Drive drive = clazz.getAnnotation(Drive.class);
			if (drive != null) {
				drives.add(drive.value().toLowerCase());
			}
		}

		return RESTResponse.of(drives).toString();

	}
}
